﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using ServBus.ListForm2010.Setup.Utilities;

namespace ServBus.ListForm2010.Setup.Commands
{
    class AddSolutionCmd : BaseCommand
    {
        public override string Description
        {
            get { return Properties.Resources.CmdAddSolution; }
        }

        public override bool Execute()
        {
            try
            {
                Log.WriteLog(Log.LogType.Info, "Starting Adding Solution...");
                SPSolution sol = SPFarm.Local.Solutions.Add(Path.Combine(Constants.EXTRACTDIRECTORY, Constants.WSPNAME));
                sol.Properties[Constants.VERSION_STRING] = Constants.VERSION;
                sol.Update();
                Log.WriteLog(Log.LogType.Info, "Solution Added.");
                return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog(Log.LogType.Error, "Add Solution Error. " + ex.GetType().FullName + ". " + ex.Message);
                return false;
            }
        }

        public override bool Rollback()
        {
            return new DeleteSolutionCmd().Execute();
        }
    }
}
